package org.rafal.springframework.controller;

import javax.inject.Inject;

import org.rafal.springframework.domain.Text;
import org.rafal.springframework.service.TextService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value="/texts")
public class TextController {
	private static final Logger logger = LoggerFactory.getLogger(TextController.class);
	private TextService textService;

	@Inject
	public TextController(TextService textService) {
		this.textService = textService;
	}
	
	@RequestMapping(method=RequestMethod.GET)
	public String showTexts(Model model) {
		
		//w celach testowych
		textService.save(new Text("sadasdasdasdadasdsadsadasda ",	 "saddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"));
		logger.info("Showing all texts.!");
		
		//List<Text> texts = textService.findAll();
		model.addAttribute("texts", textService.findAll());
		return "texts";	
	}

	
}
